#ifndef _CONSTANT_BUFFER_H_
#define _CONSTANT_BUFFER_H_

#include "./define_dx.h"

namespace ShaderSpace {

	struct CB_PER_FRAME_CONSTANTS {
		D3DXMATRIX		mViewProjection;
		D3DXVECTOR3		vCameraPosWorld;

		float				fTessellationFactor;

		int				iTimer;
		/* [0.0,1.0[ */
		float				fInterpolationTimer;

		int				iLimitTime;

		int				iQttControlPoints;

		int				iInterpolationType;

		float				fRadius;
	};

	class ConstantBuffer {
	protected:
		/*! value in cpu */
		CB_PER_FRAME_CONSTANTS *value;
		/*! mapped value for gpu use */
		ID3D11Buffer **buffer_gpu;

		CDXUTSlider *slider_timer;
		CDXUTStatic *label_timer;

	public:
		ConstantBuffer();
		ConstantBuffer( const ConstantBuffer &original );
		~ConstantBuffer();

		inline CB_PER_FRAME_CONSTANTS& getValue() const {
			return *value;
		};

		inline void setSliderTimer( CDXUTSlider* const &object, CDXUTStatic* const &label = NULL ) {
			slider_timer = object;
			label_timer = label;
		};

		void startValue( const usint number_of_points, const usint number_of_frames, const CModelViewerCamera &camera, const float &tesselation_factor = default_tesselation_factor );
		void updateValue( const CModelViewerCamera &camera, const double &elapsed_time, const float &tesselation_factor = default_tesselation_factor );

		void setTimeValue( const double &time );
		inline void updateTimeValue( const double &time ) {
			setTimeValue( value->iTimer + value->fInterpolationTimer + time );
		};

		inline ID3D11Buffer*& getBufferGPU() const {
			return *buffer_gpu;
		};

		bool createOnDevice( ID3D11Device *target_device );
		bool updateOnDeviceContext( ID3D11DeviceContext *target_device );
		bool destroy();

	};

};

#endif // _CONSTANT_BUFFER_H_
